package com.altio.swing;


import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * Listens for key events and forward them all to a given component
 * 
 * @author tomm
 *
 */
public class KeyDispatcher implements KeyListener {

  /** Component to dispatch the events to*/
  private Component toDispatchTo = null;
  
  public KeyDispatcher(Component toDispatchTo) {
    super();
    this.toDispatchTo = toDispatchTo;
  }

  public void keyPressed(KeyEvent e) {
    redispatch(e);
  }

  public void keyReleased(KeyEvent e) {
    redispatch(e);
  }

  public void keyTyped(KeyEvent e) {
    redispatch(e);
  }
  
  private void redispatch(AWTEvent e) {
    if(toDispatchTo != null) {
      toDispatchTo.dispatchEvent(e);
    }
  }

}
